/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-09-24
 * Time:15:49
 */
//JDk17语法新增特性

//密封类
//2.没有写permits，表示密封类允许被所有的子类继承
sealed class School {

}
non-sealed class Student extends School {

}
non-sealed class Teacher extends School {

}
non-sealed class Cat extends School {

}

//1.写了permits，密封类只能被允许的子类继承
/*sealed class School permits Student,Teacher {

}
non-sealed class Student extends School {

}
non-sealed class Teacher extends School {

}*/

sealed class Animal permits Dog {

}

//3.如果希望Dog类不能被任何类继承，那么声明为final
final class Dog extends Animal {

}

//2.如果希望Dog类可以被进一步继承，但仍然是受控的，可以声明为sealed
/*sealed class Dog extends Animal permits Cat {

}
non-sealed class Cat extends Dog {

}*/

//1.如果希望Dog类可以被任意继承，则声明为non-sealed
/*non-sealed class Dog extends Animal {

}*/

class Person<T,S,U,V> {
    /*
    public var name; //error 不能使⽤var来声明字段

    public var eat(var food) { //error 不能使⽤var来声明⽅法参数、不能使⽤var来声明⽅法返回类型
        var str = null; //error var声明变量必须初始化，但是不能初始化为null
    }
    */
}
public class Test {
    public static void main(String[] args) {
        //var关键字
        var name = "zhangsan";
        var age = 10;

        Integer[] integers = new Integer[10];
        Double[] doubles = new Double[10];
        Float[] floats = new Float[10];
        Byte[] bytes = new Byte[10];
        Person<Integer,Double,Float,Byte> person = new Person<Integer,Double,Float,Byte>();
        var person1 = new Person<Integer,Double,Float,Byte>();
    }
    public static void main4(String[] args) {
        String date = "one";
        int result = switch (date) {
            case "one": yield 1;
            case "two": yield 2;
            default: yield -1;
        };
        System.out.println(result);
    }
    public static void main3(String[] args) {
        //使用 -> 来代替
        String date = "one";
        int result = switch (date) {
            case "one" -> 1;
            case "two" -> 2;
            default -> -1;
        };
        System.out.println(result);
    }
    public static void main1(String[] args) {
        //yield关键字
        //正常的switch语句
        String date = "one";
        int result = 0;
        switch (date) {
            case "one":
                result = 1;
                break;
            case "two":
                result = 2;
                break;
            default:
                result = -1;
                break;
        }
        System.out.println(result);
    }
}
